//package com.hansming.bss.modules.sfc.web.front;
//
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.math.BigDecimal;
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.GregorianCalendar;
//import java.util.List;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//
//import org.springframework.ui.Model;
//import org.activiti.engine.impl.util.json.JSONArray;
//import org.activiti.engine.impl.util.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import com.hansming.bss.modules.sfc.entity.CarExtr;
//import com.hansming.bss.common.web.BaseController;
//import com.hansming.bss.modules.sfc.entity.CarDatePrice;
//import com.hansming.bss.modules.sfc.entity.CarInfo;
//import com.hansming.bss.modules.sfc.entity.CarServe;
//import com.hansming.bss.modules.sfc.entity.Contacts;
//import com.hansming.bss.modules.sfc.entity.Customer;
//import com.hansming.bss.modules.sfc.entity.SfcComments;
//import com.hansming.bss.modules.sfc.service.CarDatePriceService;
//import com.hansming.bss.modules.sfc.service.CarExtrService;
//import com.hansming.bss.modules.sfc.service.CarInfoService;
//import com.hansming.bss.modules.sfc.service.CarServeService;
//import com.hansming.bss.modules.sfc.service.ContactsService;
//import com.hansming.bss.modules.sfc.service.SfcCommentsService;
//import com.hansming.bss.modules.sfc.util.PageBean;
//import com.hansming.bss.modules.sfc.util.TimeUtil;
//
//
///**
// * 前端页面租车相关 Controller
// * @author Hansming
// * @version 2017-10-11
// */
//@Controller
//@RequestMapping(value = "/car")
//public class FrontCarinfoController extends BaseController {
//	
//	@Autowired
//	private CarInfoService carinfoService;
//	
//	@Autowired
//	private CarDatePriceService carDatePriceService;
//	
//	@Autowired
//	private SfcCommentsService commentsService;
//	
//	@Autowired
//	private CarServeService carServeService;
//	
//	@Autowired
//	private CarExtrService carExtrService;
//	
//	@Autowired
//	private ContactsService contactsService;
//	
//	@RequestMapping(value="/test")
//	public String test(String name,Model model){
//		model.addAttribute("test", "测试");
//		
//		return "modules/sfc/test";
//	}
//	
//	
//	
////	//租车查询，直接挑战租车列表页面
////	@RequestMapping(value="/search")
////	public String carSearch(String fromcityid,Date fromdate,int fromhour,String tocityid,Date todate,int tohour,CarInfo carInfo,PageBean page,int sortid,int orderid,Model model){
////		List<CarInfo> cars = carinfoService.getPageList(carInfo, page, sortid, orderid);
////		if(page == null){
////			page = new PageBean();
////		}
////        //设置每一页的显示的数量
////        page.setPageSize(12);
////		//显示出时间内最低价格为房车单价
////		for(CarInfo c:cars){
////			BigDecimal minprice = c.getPrice();
////			List<CarDatePrice> prices = carDatePriceService.getByCarId(c.getId());
////			if(prices != null){
////				for(CarDatePrice p:prices){
////					 if(minprice.compareTo(p.getPrice()) == 1 ) {
////						 minprice = p.getPrice();
////	                    }
////				}
////			}
////			c.setPrice(minprice);
////		}
////		model.addAttribute("cars", cars);
////		model.addAttribute("fromdate", fromdate);
////		model.addAttribute("fromhuor", fromhour);
////		model.addAttribute("todate", todate);
////		model.addAttribute("fromcityid", fromcityid);
////		model.addAttribute("tohuor", tohour);
////		model.addAttribute("carInfo", carInfo);
////		model.addAttribute("page", page);
////		model.addAttribute("sortid",sortid);
////		model.addAttribute("orderid",orderid);
////		return "";																						//跳转房车列表页
////	}
////	
////	//得到价格日历jsonAjax
////	@RequestMapping(value="/getprice")
////	public void getCarprice(String carid,HttpServletRequest request, HttpServletResponse response) throws IOException{
////		response.setCharacterEncoding("UTF-8");
////        response.setHeader("Cache-Control", "no-cache");
////        PrintWriter out = response.getWriter();
////        JSONObject jsonObject = new JSONObject();
////		String resCode = "1";								//返回前台的消息状态
////		String message = "";								//返回前台的消息
////		JSONArray datas = new JSONArray();		//返回到前台的具体的价格日期信息json
////		List<CarDatePrice> prices = carDatePriceService.getByCarId(carid);   //此处有错误，未能查到对应房车的价格信息
////		for(CarDatePrice p:prices){
////			JSONObject data1 =  new JSONObject();
////			data1.put("date", p.getDatetime());
////			data1.put("price",p.getPrice());
////			datas.put(data1);
////			}
////		jsonObject.put("resCode", resCode);
////		jsonObject.put("message", message);
////		jsonObject.put("data", datas);
////		out.print(jsonObject.toString());
////		out.flush();
////		out.close();
////	}
////	
////	//详情页得到房车基础信息，详细信息，房车选择服务信息，房车评论
////	@RequestMapping(value= "/getcarinfo")
////	public String toCarinfoDetail(String id,Model model){
////		CarInfo car = carinfoService.get(id);
////		CarExtr carExtr = carExtrService.getByCarid(car.getId());
////		List<CarServe> carServes = carServeService.getByCarExtrId(carExtr.getId());
//////		List<SfcComments> comments = commentsService.getByid(car.getId(), SfcComments.getCartype());
////		model.addAttribute("car",car);
////		model.addAttribute("carextr",carExtr);
////		model.addAttribute("carServes", carServes);
//////		model.addAttribute("comments", comments);
////		return "";
////	}
////	
////	
////	//传递价格清单json
////	@RequestMapping(value="/getPrice")
////	public void getPricelist(String carid,List<String> serveid,Date fromdate,int fromhour,String cityid,Date todate,int tohour,HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException{
////		response.setCharacterEncoding("UTF-8");
////        response.setHeader("Cache-Control", "no-cache");
////        PrintWriter out = response.getWriter();
////        JSONObject jsonObject = new JSONObject();
////    	String resCode = "1";								//返回前台的消息状态
////		String message = "";								//返回前台的消息	
////		JSONObject data = new 	JSONObject();	//返回到前台的具体的价格日期信息json
////		
////		Date fdate = fromdate;
////		Date tdate = todate;
////		BigDecimal totleprice = new BigDecimal("0.00");								//租车价格总价
////		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
////		if(fromhour >24)	{											//若超过中午12点，则按照翌日的价格计算，起始的结束日期加1
////			Calendar fromcal = Calendar.getInstance();
////			fromcal.setTime(fromdate);
////			fromcal.set(Calendar.DATE, fromcal.get(Calendar.DATE) + 1);
////			fdate = dft.parse(dft.format(fromcal.getTime()));
////			Calendar tocal = Calendar.getInstance();
////			tocal.setTime(todate);
////			tocal.set(Calendar.DATE, tocal.get(Calendar.DATE) + 1);
////			tdate = dft.parse(dft.format(tocal.getTime()));
////		}		
////		
////			int hour = 0;										//多出整天数的时间，超过四小时算作一天，若不超过，按照比例每半小时为该天价格的1/16，单位为半小时
////			int resulthour =tohour - fromhour; 					//根据取车的时间 fromhour 为 取车时间的id,id为0 = 00:00,id为1 = 00:30以此为例（tohour 同理)
////			BigDecimal extrPrice = new BigDecimal("0.00");				//超出整天数的小时所产生的额外价格
////			if(resulthour >= 0 ){
////				//超过一天的时间
////				if(resulthour >8){
////					Calendar tocal = Calendar.getInstance();			//days = days +1;
////					tocal.setTime(todate);
////					tocal.set(Calendar.DATE, tocal.get(Calendar.DATE) + 1);
////				}else{
////					hour = resulthour;						//此为小时数为超过整天数4小时内，按每半小时当天单价的1/16计价	
//////
//////					
//////					extrPrice = carDatePriceService.getByDate(dft.format(todate)).getPrice().divide(new BigDecimal("16")).multiply(new BigDecimal(String.valueOf(hour)));
////				}
////		}else{
////			//未超过一天时间
////			//正常计价，未有变化
////		}
////			
////			List<CarDatePrice> carPrices = null;
//////			carPrices = carDatePriceService.getByDateFrom(dft.format(fdate),dft.format(tdate));
//////			if(carPrices != null){
//////				for(CarDatePrice p:carPrices){
//////					totleprice = totleprice.add(p.getPrice());
//////				}
//////		}
////		data.put("车辆租金",totleprice);
////		
////		
////		int days = TimeUtil.Datecalc(dft.format(fromdate),dft.format(todate)); 
////		BigDecimal price = new BigDecimal("0");
////		for(String i:serveid){
////			CarServe serve = carServeService.get(i);
//////			if(serve.getForeach() == CarServe.getSelectedFlag()){		//提供的服务是否是按天数计费
//////				if(serve.getFornatural() == CarServe.getSelectedFlag()){					//是否是按照按自然天数计费（自然天数比普通按天数计费加1天）
//////					price =  serve.getCar_item_price().multiply(new BigDecimal(String.valueOf(days+1)));
//////					data.put("name",serve.getCar_item()+"("+(days+1)+"天)");
//////				}else{
//////					price =  serve.getCar_item_price().multiply(new BigDecimal(String.valueOf(days)));
//////					data.put("name",serve.getCar_item()+"("+days+"天)");
//////				}	
//////		}else{
//////					price = extrPrice.add(serve.getCar_item_price());
//////		}
////			
////			data.put("price",price);
////	}
////        jsonObject.put("data",data);
////		jsonObject.put("resCode", resCode);
////		jsonObject.put("message", message);
////		jsonObject.put("data", data);
////		out.print(jsonObject.toString());
////		out.flush();
////		out.close();
////	}
////	
////	
////	//跳转填写订单页面
////	@RequestMapping(value="writeOrder")
////	public String writeOrder(String carid,List<String> serveid,String cityid,Date fromdate,int fromhour,Date todate,int tohour,CarDatePrice carDatePrice,Model model,HttpServletRequest request, HttpServletResponse response) throws ParseException{
////		CarInfo car = carinfoService.get(carid);
////		HttpSession session = request.getSession();
////		Customer user = (Customer) session.getAttribute("cus");
////		List<Contacts> contacts = contactsService.getContactsByuserId(user.getId());		
////		model.addAttribute("contacts", contacts);
////		model.addAttribute("serves",serveid);
////		model.addAttribute("car",car );
////		model.addAttribute("fromdate",fromdate);
////		model.addAttribute("todate",todate);
////		model.addAttribute("fromhour",fromhour);
////		model.addAttribute("tohour",tohour);		
////	return "";
////			/**
////				*价格的计算，在跳转入房车订单填写的页面并没有用到
////				*/
//////		Date fdate = fromdate;
//////		Date tdate = todate;	
//////		BigDecimal totleprice = new BigDecimal("0.00");								//租车价格总价
//////		List<CarDatePrice> carPrices = null;
//////		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
//////		if(fromhour >24)	{											//若超过中午12点，则按照翌日的价格计算，起始的结束日期加1
//////			Calendar fromcal = Calendar.getInstance();
//////			fromcal.setTime(fromdate);
//////			fromcal.set(Calendar.DATE, fromcal.get(Calendar.DATE) + 1);
//////			fdate = dft.parse(dft.format(fromcal.getTime()));
//////			Calendar tocal = Calendar.getInstance();
//////			tocal.setTime(todate);
//////			tocal.set(Calendar.DATE, tocal.get(Calendar.DATE) + 1);
//////			tdate = dft.parse(dft.format(tocal.getTime()));
//////		}					
//////			
//////			int hour = 0;				//多出整天数的时间，超过四小时算作一天，若不超过，按照比例每半小时为该天价格的1/16，单位为半小时
//////			int resulthour =tohour - fromhour; 					//根据取车的时间 fromhour 为 取车时间的id,id为0 = 00:00,id为1 = 00:30以此为例（tohour 同理)
//////			BigDecimal extrPrice = new BigDecimal("0.00");				//超出整天数的小时所产生的额外价格
//////			if(resulthour >= 0 ){
//////				//超过一天的时间
//////				if(resulthour >8){
//////					Calendar tocal = Calendar.getInstance();			//days = days +1;
//////					tocal.setTime(todate);
//////					tocal.set(Calendar.DATE, tocal.get(Calendar.DATE) + 1);
//////				}else{
//////					hour = resulthour;						//此为小时数为超过整天数4小时内，按每半小时当天单价的1/16计价	
//////					extrPrice = carDatePriceService.getByDate(dft.format(todate)).getPrice().divide(new BigDecimal("16")).multiply(new BigDecimal(String.valueOf(hour)));
//////				}
//////		}else{
//////			//未超过一天时间
//////			//正常计价，未有变化
//////		}
//////			carPrices = carDatePriceService.getByDateFrom(dft.format(fdate),dft.format(tdate));
//////			if(carPrices != null){
//////				for(CarDatePrice p:carPrices){
//////					totleprice = totleprice.add(p.getPrice());
//////				}
//////			} 			
//////					
//////			
//////			int days = 0;		//计价的自然天数或天数，注：租车时间1月1日 8：00-1月2日8：00，普通计数天数为1天，自然天数为2天。
//////			days = TimeUtil.Datecalc(dft.format(fromdate),dft.format(todate));
//////			for(String i:serveid){
//////					CarServe serve = carServeService.get(i);
//////					if(serve.getForeach() == CarServe.getSelectedFlag()){		//提供的服务是否是按天数计费
//////						if(serve.getFornatural() == CarServe.getSelectedFlag()){					//是否是按照按自然天数计费（自然天数比普通按天数计费加1天）
//////								extrPrice = extrPrice.add(serve.getCar_item_price().multiply(new BigDecimal(String.valueOf(days+1))));					
//////						}else{
//////							extrPrice = extrPrice.add(serve.getCar_item_price().multiply(new BigDecimal(String.valueOf(days))));
//////						}	
//////				}else{
//////					extrPrice = extrPrice.add(serve.getCar_item_price());
//////				}
//////			}
//////			totleprice = totleprice.add(extrPrice);
////			
////
////	}
////	
////	
////	//订单填写页面联系人传递的json
////	@RequestMapping(value = "/getcontacts")
////	public void getContactsinfo(String id,HttpServletRequest request, HttpServletResponse response) throws IOException {
////		response.setCharacterEncoding("UTF-8");
////        response.setHeader("Cache-Control", "no-cache");
////        PrintWriter out = response.getWriter();
////        JSONObject jsonObject = new JSONObject();
////    	String resCode = "1";								//返回前台的消息状态
////		String message = "";								//返回前台的消息
////		JSONObject data = new 	JSONObject();	//返回到前台的具体的价格日期信息json
////		Contacts contact = contactsService.getByid(id);
////		data.put("name",contact.getCname());
////		data.put("identType",contact.getIdenttype());
////		data.put("identNum",contact.getIdentnum());
////		data.put("email",contact.getEmail());
////		data.put("phone",contact.getPhone());
////		jsonObject.put("resCode", resCode);
////		jsonObject.put("message", message);
////		jsonObject.put("data", data);
////		out.print(jsonObject.toString());
////		out.flush();
////		out.close();
////	}
//}
//
//	
